#include <vector>
#include <iostream>
#include <queue>
using namespace std;
class Solution
{
public:
    int magicTower(vector<int> &nums)
    {
        long long heal = 1;
        priority_queue<int, vector<int>, greater<int>> queue;
        int len = nums.size();
        int ans = 0;
        long long last = 0;
        for (int i = 0; i < len; i++)
        {
            heal += (long long)nums[i];
            if (nums[i] < 0)
            {
                queue.push(nums[i]);
            }
            while(heal <= 0){
                long long  h = queue.top();
                queue.pop();
                heal -= h;
                last += h;
                ans++;
            }
        }
        if(heal + last < 0){
            return -1;
        }else{
            return ans;
        }
    }
};
int main(int argc, char const *argv[])
{
    Solution s ;
    // vector<int> v{100,100,100,-250,-60,-140,-50,-50,100,150};
    vector<int> v{-200,-300,400,0};
    int a = s.magicTower(v);
    cout << a << endl;
    return 0;
}
